import actionTypes from './actionTypes'

// 2.获取actiontype
const handleSeeting = () => {
    return {
        type: actionTypes.SETTING_THEME
    }
}

// 设置成功之后的请求
const seetingSuccess = (data) => {
    return {
        type: actionTypes.SEETING_THEME_SUCCESS,
        payload: {
            data
        }
    }
}

export const seetingHandle = () => {
    return dispatch => {
        // 派送actiontype
        dispatch(handleSeeting())
        getSomeData()
            .then(resp => {
                dispatch(seetingSuccess(resp))
            })
    }
}

// 模拟一个promise
const getSomeData = () => {
    return new Promise((res, rej) => {
        setTimeout(() => {
            res({
                id: '1',
                name: 'zhangshan',
                sex: 'nan',
                age: 12
            })
        }, 2000)
    })
}